package com.demo.jenkins;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.threadpool.TtlExecutors;

import java.util.concurrent.*;

public class TTLDemo {

    public static void main(String[] args) {
        TransmittableThreadLocal<String> threadLocal = new TransmittableThreadLocal<>();
        threadLocal.set("线程池参数：pool");
        //创建线程池
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                3,
                10,
                100,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(6),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        Executor ttlExecutor = TtlExecutors.getTtlExecutor(poolExecutor);
        ttlExecutor.execute(()->{
            System.out.println(Thread.currentThread().getName()+"取了参数，参数值为："+threadLocal.get());
        });
        ttlExecutor.execute(()->{
            System.out.println(Thread.currentThread().getName()+"取了参数，参数值为："+threadLocal.get());
        });

    }
}
